package team.nmsg.photo.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;

import team.nmsg.ge.system.interf.ISysBean;
import team.nmsg.ge.system.util.ServerParams;
import team.nmsg.photo.PhotoUtil;

@Entity
public class ProjectBean implements ISysBean{
	
	private static Logger log = LoggerFactory.getLogger(ProjectBean.class);

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long projectId;
	
	private Long createTime;
	
	private Long endTime;// 结束时间
	
	private Long updateTime; // 开始时间
	
	private String projectSeq;//项目编号
	
	private String proTitle;
	
	@Column(length=1024)
	private String proDesc;
	
	private String shareTitle;
	
	@Column(length=1024)
	private String shareDesc;
	
	@Column(length=256)
	private String imgBaseDir;	// 项目资源基路径
	
	private String coverImg;  //封面图片
	private String shareIconImg;// 分享icon img
	private String advertiseImg;//  广告图片
	
	private Integer status ;    //  0未开始 1开始  2 完毕 
	
	private Integer isShow = 0; // 0显示 ，   1 不显示
	
	private Integer picNum = 0 ;
	private Integer accessCount = 0;
	
	private String classtype = "['"+PhotoUtil.pro_type_default+"']";
	private Integer sOrder  = 10000;  //推荐
	
	private String standby1;
	private String standby2;
	private String standby3;
	private String standby4;
	private String standby5;
	
	public Long getProjectId() {
		return projectId;
	}

	public void setProjectId(Long projectId) {
		this.projectId = projectId;
	}

	public Long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	public Long getEndTime() {
		return endTime;
	}

	public void setEndTime(Long endTime) {
		this.endTime = endTime;
	}

	public Long getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Long updateTime) {
		this.updateTime = updateTime;
	}

	public String getProjectSeq() {
		return projectSeq;
	}

	public void setProjectSeq(String projectSeq) {
		this.projectSeq = projectSeq;
	}

	public String getProTitle() {
		return proTitle;
	}

	public void setProTitle(String proTitle) {
		this.proTitle = proTitle;
	}

	public String getProDesc() {
		return proDesc;
	}

	public void setProDesc(String proDesc) {
		this.proDesc = proDesc;
	}

	public String getShareTitle() {
		return shareTitle;
	}

	public void setShareTitle(String shareTitle) {
		this.shareTitle = shareTitle;
	}

	public String getShareDesc() {
		return shareDesc;
	}

	public void setShareDesc(String shareDesc) {
		this.shareDesc = shareDesc;
	}

	public String getImgBaseDir() {
		return imgBaseDir;
	}

	public void setImgBaseDir(String imgBaseDir) {
		this.imgBaseDir = imgBaseDir;
	}

	public String getCoverImg() {
		return coverImg;
	}

	public void setCoverImg(String coverImg) {
		this.coverImg = coverImg;
	}

	public String getShareIconImg() {
		return shareIconImg;
	}

	public void setShareIconImg(String shareIconImg) {
		this.shareIconImg = shareIconImg;
	}

	public String getAdvertiseImg() {
		return advertiseImg;
	}

	public void setAdvertiseImg(String advertiseImg) {
		this.advertiseImg = advertiseImg;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getIsShow() {
		return isShow;
	}

	public void setIsShow(Integer isShow) {
		this.isShow = isShow;
	}

	public Integer getPicNum() {
		return picNum;
	}

	public void setPicNum(Integer picNum) {
		this.picNum = picNum;
	}

	public Integer getAccessCount() {
		return accessCount;
	}

	public void setAccessCount(Integer accessCount) {
		this.accessCount = accessCount;
	}

	public String getStandby1() {
		return standby1;
	}

	public void setStandby1(String standby1) {
		this.standby1 = standby1;
	}

	public String getStandby2() {
		return standby2;
	}

	public void setStandby2(String standby2) {
		this.standby2 = standby2;
	}

	public String getStandby3() {
		return standby3;
	}

	public void setStandby3(String standby3) {
		this.standby3 = standby3;
	}

	public String getStandby4() {
		return standby4;
	}

	public void setStandby4(String standby4) {
		this.standby4 = standby4;
	}
	
	public String getClasstype() {
		return classtype;
	}

	public void setClasstype(String classtype) {
		this.classtype = classtype;
	}

	public Integer getsOrder() {
		return sOrder;
	}

	public void setsOrder(Integer sOrder) {
		this.sOrder = sOrder;
	}

	public String getStandby5() {
		return standby5;
	}

	public void setStandby5(String standby5) {
		this.standby5 = standby5;
	}
	

	@Override
	public JSONObject toJson() {
		
		JSONObject json = (JSONObject) JSONObject.toJSON(this);
		
		Long updateTime = this.getUpdateTime();
		if(  updateTime!=null ) {
			json.put("updateTime", PhotoUtil.formatDate(updateTime) );
		}
		Long endTime = this.getEndTime();
		if(  endTime!=null ) {
			json.put("endTime", PhotoUtil.formatDate(endTime) );
		}
		
		String img1 = imgBaseDir  +this.getCoverImg();
		String img2 = imgBaseDir  +this.getShareIconImg();
		String img3 = imgBaseDir +this.getAdvertiseImg();
		
		json.put("coverImg", img1 );
		json.put("shareIconImg", img2 );
		json.put("advertiseImg", img3 );
		
		json.put("accessUrl", ServerParams.photomurl+projectId );
		
		return json;
	}
	
	public static ProjectBean fromJsonStr(String str) {
		
		JSONObject object = JSONObject.parseObject(str);
		
//		String updateTimeStr = object.getString("updateTime");
//		String endTimeStr = object.getString("endTime");
//		try {
//			Long st = PhotoUtil.parseStrDate(updateTimeStr);
//			Long et = PhotoUtil.parseStrDate(endTimeStr);
//			
//			object.put( "updateTime", st);
//			object.put( "endTime", et);
//			
//		} catch (Exception e) {
//			log.error( "" ,e );
//		}
		
		ProjectBean javaObject = object.toJavaObject(ProjectBean.class);
		
//		ProjectBean parseObject = JSONObject.parseObject(str, ProjectBean.class);
		
		return javaObject;
	}

}
